package com.lmmob.autotest.uitest.controls;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import java.util.concurrent.TimeUnit;

public class Button extends Control {
    private String text;

    public Button(String text, WebDriver webDriver) {
        super(webDriver);
        this.text = text;
    }

    @Override
    protected String getSelfQuery() {
        return String.format(".query(\"button[text='%s']\")[0]", text);
    }

    public void click() {
        findElement(By.id(getId())).click();
        waitAWhile(2L, TimeUnit.SECONDS);
    }

    @Override
    protected String getName(){
        return this.text;
    }
}
